<?php

namespace app\admin\model;

use think\Model;
use traits\model\SoftDelete;

class Project extends Model
{

    use SoftDelete;

    

    // 表名
    protected $name = 'project';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'integer';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    protected $deleteTime = 'deletetime';

    // 追加属性
    protected $append = [

    ];

    public function getTenderTypeList()
    {
        return ['1' => __('Tender_type 1'), '2' => __('Tender_type 2') ];
    }

    public function base($query)
    {
        $query->alias('project')->where('project.caijiakuid',CAIJIAKU_ID)->useSoftDelete($this->deleteTime);
    }
    
    public static function init()
    {
        self::beforeInsert(function ($row) {
            $row->caijiakuid = CAIJIAKU_ID;
        });
    }

    // 在保存前处理空值
    public function setStartDateAttr($value)
    {
        return !empty($value) ? $value : null;
    }

    public function setEndDateAttr($value)
    {
        return !empty($value) ? $value : null;
    }

    public function setRealStartDateAttr($value)
    {
        return !empty($value) ? $value : null;
    }
    public function setRealEndDateAttr($value)
    {
        return !empty($value) ? $value : null;
    }
    public function setSeniorEditorDateAttr($value)
    {
        return !empty($value) ? $value : null;
    }
    public function setPreparedDateAttr($value)
    {
        return !empty($value) ? $value : null;
    }

    public function admin()
    {
        return $this->belongsTo('app\admin\model\Admin', 'admin_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }

    







}
